/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.AttributeInfo;
/*     */ import com.zimbra.cs.account.AttributeManager;
/*     */ import com.zimbra.cs.account.FileGenUtil;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.TreeSet;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetAttributeInfo
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  39 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  41 */     String[] attrs = null;
/*  42 */     String attrsRequested = request.getAttribute("attrs", null);
/*  43 */     if (attrsRequested != null) {
/*  44 */       attrs = attrsRequested.split(",");
/*     */     }
/*     */     
/*  47 */     String[] entryTypes = null;
/*  48 */     String entryTypesRequested = request.getAttribute("entryTypes", null);
/*  49 */     if (entryTypesRequested != null) {
/*  50 */       entryTypes = entryTypesRequested.split(",");
/*     */     }
/*     */     
/*  53 */     if ((attrs != null) && (entryTypes != null)) {
/*  54 */       throw ServiceException.INVALID_REQUEST("only one of attrs or entryTypes can be specified", null);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  59 */     AttributeManager attrMgr = AttributeManager.getInstance();
/*     */     
/*  61 */     Element response = zsc.createElement(AdminConstants.GET_ATTRIBUTE_INFO_RESPONSE);
/*     */     
/*  63 */     if (attrs != null) {
/*  64 */       for (String attr : attrs) {
/*  65 */         encodeAttr(response, attrMgr, attr.trim());
/*     */       }
/*  67 */     } else if (entryTypes != null) {
/*  68 */       for (String entry : entryTypes) {
/*  69 */         AttributeClass attrClass = AttributeClass.fromString(entry.trim());
/*  70 */         TreeSet<String> attrsOnEntry = new TreeSet(attrMgr.getAllAttrsInClass(attrClass));
/*  71 */         for (String attr : attrsOnEntry) {
/*  72 */           encodeAttr(response, attrMgr, attr);
/*     */         }
/*     */         
/*     */       }
/*     */       
/*     */ 
/*     */     }
/*     */     else
/*     */     {
/*  81 */       TreeSet<String> allAttrs = new TreeSet();
/*  82 */       for (AttributeClass ac : AttributeClass.values()) {
/*  83 */         allAttrs.addAll(attrMgr.getAllAttrsInClass(ac));
/*     */       }
/*     */       
/*  86 */       for (String attr : allAttrs) {
/*  87 */         encodeAttr(response, attrMgr, attr);
/*     */       }
/*     */     }
/*     */     
/*  91 */     return response;
/*     */   }
/*     */   
/*     */   private void encodeAttr(Element response, AttributeManager attrMgr, String attr) {
/*  95 */     AttributeInfo attrInfo = attrMgr.getAttributeInfo(attr);
/*     */     
/*  97 */     if (attrInfo == null) {
/*  98 */       ZimbraLog.account.info("no attribte info for " + attr);
/*  99 */       return;
/*     */     }
/*     */     
/* 102 */     String desc = attrInfo.getDescription();
/* 103 */     String deSpacedDesc = FileGenUtil.wrapComments(desc == null ? "" : desc, Integer.MAX_VALUE, "");
/*     */     
/* 105 */     Element eAttr = response.addElement("a");
/* 106 */     eAttr.addAttribute("n", attr);
/* 107 */     eAttr.addAttribute("desc", deSpacedDesc);
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 112 */     notes.add("Do not need any right, all admins are allowed.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetAttributeInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */